package com.kukudb.asaproject.controller.api;


import com.kukudb.asaproject.pojo.CardKeys;
import com.kukudb.asaproject.pojo.ResponseMessage;
import com.kukudb.asaproject.pojo.User;
import com.kukudb.asaproject.serveice.CardKeysImpl;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController     //接口方法返回对象  转换成json数据
@RequestMapping("/api/server/admin")    // localhost:81/api/user
public class CardKeysAdminApi {
    @Autowired
    CardKeysImpl cardKeysImpl ;

    Logger logger = LoggerFactory.getLogger(CardKeysApi.class);
    @GetMapping("/getAllCardKeys")
    public ResponseMessage<List<CardKeys>> getAllCardKeys(HttpSession session) {
        User user = (User) session.getAttribute("user");
        logger.info("userId: " + user.getUserId());
        if(!"0".equals(user.getRole())){
            return new ResponseMessage(400, "error", "权限不足");
        }
        List<CardKeys> cardKeys = cardKeysImpl.getAllCardKeys();
        return new ResponseMessage(200, "success", cardKeys);
    }


}
